<extend name="Base/base" />
<block name="button">
	<a href="{:U('oper')}" class="btn btn-primary"><i class="fa fa-plus"></i> {:L('text_add')}</a>
	<button class="btn btn-danger" data-toggle="btn-delete" confirm="{:L('warning_delete_title')}" confirm-info="{:L('warning_delete_text')}" type="submit" form="form"><i class="fa fa-trash"></i> {:L('text_delete')}</button>
</block>
<block name="body">
	<div class="panel panel-default">
		<div class="panel-heading">
			<h3><i class="fa fa-list"></i>   {$heading_title|default=L('heading_title')}</h3>
		</div>
		<div class="panel-body">
			<div class="well">
				<div class="row">
					<div class="col-sm-4">
						<div class="form-group">
			                <label class="control-label" for="input-title">{:L('entry_title')}</label>
			                <input type="text" name="filter_title"  placeholder="{:L('entry_title')}" id="input-title" class="form-control" value="{$filter_data['title']|default=''}" autocomplete="off">
			            </div>
					</div>
					<div class="col-sm-4">
						<div class="form-group">
			                <label class="control-label" for="input-category">{:L('entry_category')}</label>
			                <input type="text" name="article_category_title" value="{$filter_data.article_category_title|default=''}" placeholder="{:L('entry_category')}" id="input-category" class="form-control" autocomplete="off">
			                <input type="hidden" name="article_category_id" value="{$filter_data.article_category_id|default=''}">
			            </div>
					</div>
					<div class="col-sm-4">
						<div class="form-group">
						<label class="control-label"> &nbsp; </label>
			            <br>
						<button class="btn btn-primary" id="button-filter"><i class="fa fa-search"></i> {:L('button_filter')}</button>
						</div>
					</div>
				</div>
			</div>
			<if condition="empty($list)">
				<h4 class="text-center">{:L('info_no_result')}</h4>
			<else/>
			<form method="post" action="{:U('del')}" enctype="multipart/form-data" id="form">
				<table class="table table-bordered table-hover">
					<thead>
						<tr>
						<th class="text-center" style="width:50px;"><input type="checkbox" data-toggle="js-checked-all"></th>
						<th class="text-center">{:L('column_thumb')}</th>
						<th>{:L('column_title')}</th>
						<th class="status-column">{:L('text_status')}</th>
						<th class="text-right action-column">{:L('text_action')}</th>
						</tr>
					</thead>
					<tbody>
						<foreach name="list" item="item">
						<tr>
							<td class="text-center"><input type="checkbox" name="selected[]" value="{$item.article_id}"></td>
							<td class="list-thumb"><img src="{$item['thumb']}"></td>
							<td>{$item.title}</td>
							<td>{$item.status|status_to_text=###}</td>
							<td class="text-right">
								<a data-toggle="tooltip" title="{:L('text_edit')}" href="{:U('oper?article_id='.$item['article_id'],$url)}" class="btn btn-primary"><i class="fa fa-pencil"></i> </a>
							</td>
						</tr>
						</foreach>
					</tbody>
				</table>
			</form>
			</if>
		</div>
		<div class="panel-footer">
			<nav>
				<ul class="pagination">
				{$page}
				</ul>
			</nav>
		</div>
	</div>
</block>
<block name="script">
	<script type="text/javascript">
		//文章
		var autourl='{:U("autocomplete")}';
		$('input[name=\'filter_title\']').autocomplete({'source': function(request, response) {
				$.ajax({
					url: autourl + (autourl.indexOf('?')<0?'?':'&') + 'filter_title=' +  encodeURIComponent(request),
					dataType: 'json',
					success: function(json) {
						response($.map(json, function(item) {
							return {
								label: item['title'],
								value: item['article_id']
							}
						}));
					}
				});
			},
			'select': function(item) {
				$('input[name=\'filter_title\']').val(item['label']);
			}
		});
		//文章分类
		var cateurl='{:U("ArticleCategory/autocomplete")}';
		$('input[name=\'article_category_title\']').autocomplete({'source': function(request, response) {
				$.ajax({
					url: cateurl + (cateurl.indexOf('?')<0?'?':'&') + 'article_category_title=' +  encodeURIComponent(request),
					dataType: 'json',
					success: function(json) {						
						response($.map(json, function(item) {
							return {
								label: item['html'] + item['title'],
								value: item['article_category_id']

							}
						}));
					}
				});
			},
			'select': function(item) {
				$('input[name=\'article_category_title\']').val(item['label']);

				$('input[name=\'article_category_id\']').val(item['value']);
			}
		});

		var searchurl='{:U("index")}';
		$("#button-filter").on('click',function(){
			var filter_title=$('input[name="filter_title"]').val();
			if(filter_title){
				searchurl	+=	url_splice(searchurl) + "title=" + encodeURIComponent(filter_title);
			}
			var article_category_id=$('input[name="article_category_id"]').val();
			var article_category_title=$('input[name="article_category_title"]').val();
			if(article_category_id && article_category_title){
				searchurl	+=	url_splice(searchurl) + "article_category_id=" + encodeURIComponent(article_category_id);
			}
			location=searchurl;
		});
	</script>
</block>